home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / progwin.zip / MFRESORC.ZIP / MFRESORC.C next >
C/C++ Source or Header  |  1991-11-10  |  3KB  |  101 lines

  1. /*------------------------------------------
  2.   MFRESORC.C -- Metafile Resource Program
  3.                 (c) Charles Petzold, 1990
  4.   ------------------------------------------*/
  5.  
  6. #include <windows.h>
  7.  
  8. long FAR PASCAL WndProc(HWND, WORD, WORD, LONG);
  9.  
  10. int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance,
  11.                    LPSTR lpszCmdLine, int nCmdShow)
  12. {
  13.   static char szAppName[] = "MFResorc";
  14.   HWND hwnd;
  15.   MSG msg;
  16.   WNDCLASS wndclass;
  17.  
  18.   if (!hPrevInstance)
  19.   {
  20.     wndclass.style = CS_HREDRAW | CS_VREDRAW;
  21.     wndclass.lpfnWndProc = WndProc;
  22.     wndclass.cbClsExtra = 0;
  23.     wndclass.cbWndExtra = 0;
  24.     wndclass.hInstance = hInstance;
  25.     wndclass.hIcon = NULL;
  26.     wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
  27.     wndclass.hbrBackground = GetStockObject(WHITE_BRUSH);
  28.     wndclass.lpszMenuName = NULL;
  29.     wndclass.lpszClassName = szAppName;
  30.  
  31.     RegisterClass(&wndclass);
  32.   }
  33.  
  34.   hwnd = CreateWindow(szAppName, "Metafile Resource Program",
  35.                       WS_OVERLAPPEDWINDOW,
  36.                       CW_USEDEFAULT, CW_USEDEFAULT,
  37.                       CW_USEDEFAULT, CW_USEDEFAULT,
  38.                       NULL, NULL, hInstance, NULL);
  39.  
  40.   ShowWindow(hwnd, nCmdShow);
  41.   UpdateWindow(hwnd);
  42.  
  43.   while(GetMessage(&msg, NULL, 0, 0))
  44.   {
  45.     TranslateMessage(&msg);
  46.     DispatchMessage(&msg);
  47.   }
  48.   return msg.wParam;
  49. }
  50.  
  51. long FAR PASCAL WndProc(HWND hwnd, WORD message, WORD wParam, LONG lParam)
  52. {
  53.   static HANDLE hmf;
  54.   static short cxClient, cyClient;
  55.   HANDLE hInstance, hResource;
  56.   HDC hdc;
  57.   PAINTSTRUCT ps;
  58.   short x, y;
  59.  
  60.   switch (message)
  61.   {
  62.     case WM_CREATE:
  63.       hInstance = ((LPCREATESTRUCT) lParam) -> hInstance;
  64.       hResource = LoadResource(hInstance,
  65.                   FindResource(hInstance, "MyLogo", "METAFILE"));
  66.  
  67.       LockResource(hResource);
  68.       hmf = SetMetaFileBits(hResource);
  69.       UnlockResource(hResource);
  70.       return 0;
  71.  
  72.     case WM_SIZE:
  73.       cxClient = LOWORD(lParam);
  74.       cyClient = HIWORD(lParam);
  75.       return 0;
  76.  
  77.     case WM_PAINT:
  78.       hdc = BeginPaint(hwnd, &ps);
  79.  
  80.       SetMapMode(hdc, MM_ANISOTROPIC);
  81.       SetWindowExt(hdc, 1000, 1000);
  82.       SetViewportExt(hdc, cxClient, cyClient);
  83.  
  84.       for (x=0; x<10; x++)
  85.         for (y=0; y<10; y++)
  86.         {
  87.           SetWindowOrg(hdc, -100 * x, -100 * y);
  88.           PlayMetaFile(hdc, hmf);
  89.         }
  90.  
  91.       EndPaint(hwnd, &ps);
  92.       return 0;
  93.  
  94.     case WM_DESTROY:
  95.       DeleteMetaFile(hmf);
  96.       PostQuitMessage(0);
  97.       return 0;
  98.   }
  99.   return DefWindowProc(hwnd, message, wParam, lParam);
  100. }
  101.